package com.bingxue.edu.framework.common.model;

import com.bingxue.edu.framework.enums.DictEnum;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * 键值对信息
 *
 * @param <T>
 * @author panbo
 * @since 2024/6/26
 */
@SuppressWarnings("rawtypes")
@Data
@Schema(description = "键值对信息")
public class LabelValue<T> {

    /**
     * 标签
     */
    @Schema(description = "标签", example = "男")
    private String label;

    /**
     * 值
     */
    @Schema(description = "值", example = "1")
    private T value;

    /**
     * 是否禁用
     */
    @Schema(description = "是否禁用", example = "false")
    private Boolean disabled;

    /**
     * 扩展
     */
    @Schema(description = "扩展")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Map<String, Object> extend;

    private LabelValue() {
    }

    public LabelValue(String label, T value) {
        this.label = label;
        this.value = value;
        this.disabled = false;
    }

    public LabelValue(DictEnum<T> dict) {
        this.label = dict.getLabel();
        this.value = dict.getValue();
        this.disabled = dict.isDisabled();
        put("color", dict.getColor());
    }

    public LabelValue put(String key, Object value) {
        if (extend == null) {
            extend = new HashMap<>();
        }
        this.extend.put(key, value);
        return this;
    }

}
